/*
 * @(#) BaseDao.java 2010-9-6
 *
 * Copyright (c) 2010, Strong Technology. All Rights Reserved.
 * Strong Technology. CONFIDENTIAL
 */
package cn.strong.gweva.common.integration.dao.impl;

import org.springframework.orm.ibatis.support.SqlMapClientDaoSupport;

import cn.strong.gweva.common.ibatisext.PagerSqlExecutor;
import cn.strong.gweva.common.util.ReflectUtil;

import com.ibatis.sqlmap.client.SqlMapClient;
import com.ibatis.sqlmap.engine.execution.SqlExecutor;
import com.ibatis.sqlmap.engine.impl.SqlMapClientImpl;

/**
 * 分页处理Dao基类
 * 
 * @author lilanfei
 * @version 1.0
 * @since 2010-9-6
 */

public abstract class BaseDao extends SqlMapClientDaoSupport
{

	//分页处理SQL执行器
	private SqlExecutor sqlExecutor;

	/**
	 * @return sqlExecutor
	 */
	public SqlExecutor getSqlExecutor()
	{
		return sqlExecutor;
	}

	/**
	 * @param sqlExecutor sqlExecutor
	 */
	public void setSqlExecutor(SqlExecutor sqlExecutor)
	{
		this.sqlExecutor = sqlExecutor;
	}
	/**
	 * 设定是否可以执行Limit处理
	 * @param enableLimit
	 */
	public void setEnableLimit(boolean enableLimit)
	{
		if (sqlExecutor instanceof PagerSqlExecutor)
		{
			((PagerSqlExecutor)sqlExecutor).setEnableLimit(enableLimit);
		}
	}
	/**
	 * 初始化处理
	 */
	public void initialize() throws Exception
	{
		if (sqlExecutor != null)
		{
			//SQLMAP客户端
			SqlMapClient sqlMapClient = getSqlMapClientTemplate().getSqlMapClient();
			if (sqlMapClient instanceof SqlMapClientImpl)
			{
				ReflectUtil.setFieldValue(((SqlMapClientImpl)sqlMapClient).getDelegate(),
						"sqlExecutor", SqlExecutor.class, sqlExecutor);
			}
		}
	}
}
